/*
# Copyright (C) 2024 HiHope Open Source Organization .
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
 */
//头文件引入
#include "securec.h"               // 安全函数库（如memcpy_s）
#include "sle_device_discovery.h"  // SLE设备发现相关API
#include "sle_connection_manager.h"// SLE连接管理
#include "sle_ssap_client.h"       // SSAP（服务发现协议）客户端
#include "../inc/SLE_OLED_Client.h" // 自定义OLED客户端头文件
#include "soc_osal.h"              // 操作系统抽象层（如线程、锁）
#include "app_init.h"              // 应用初始化
#include "common_def.h"            // 通用定义（如错误码）
#include "debug_print.h"           // 调试打印
#include "pinctrl.h"               // 引脚控制
#include "gpio.h"                  // GPIO操作

//关于oled的头文件
#include "i2c.h"
#include "osal_debug.h"
#include "ssd1306_fonts.h"
#include "ssd1306.h"


//宏定义
#define SLE_MTU_SIZE_DEFAULT 300       // 默认MTU（最大传输单元）大小
#define SLE_SEEK_INTERVAL_DEFAULT 100  // 扫描间隔（单位可能是ms）
#define SLE_SEEK_WINDOW_DEFAULT 100    // 扫描窗口
#define UUID_16BIT_LEN 2               // 16位UUID长度
#define UUID_128BIT_LEN 16             // 128位UUID长度

//OLED相关
#define CONFIG_I2C_SCL_MASTER_PIN 15
#define CONFIG_I2C_SDA_MASTER_PIN 16
#define CONFIG_I2C_MASTER_PIN_MODE 2
#define I2C_MASTER_ADDR 0x0
#define I2C_SLAVE1_ADDR 0x38
#define I2C_SET_BANDRATE 400000
#define I2C_TASK_STACK_SIZE 0x1000
#define I2C_TASK_PRIO 17


//全局变量
static sle_announce_seek_callbacks_t g_seek_cbk = {0};//扫描回调函数组

static sle_connection_callbacks_t g_connect_cbk = {0};//连接回调函数组

static ssapc_callbacks_t g_ssapc_cbk = {0};//SSAP回调函数组

static sle_addr_t g_remote_addr = {0};//远程设备地址
uint8_t myphoto[][1024]={
    //  下面这个没问题 开心
     {0x1F,0xEF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x0F,0xFF,0xF8,0x1F,0x9F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFC,0x1E,0x1F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xFF,0xFC,0x0F,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0x06,0xFF,0x00,0x00,0x00,0x04,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0x1F,0xFE,0x00,0x00,0x00,0x04,0x00,0x00,0x40,0x00,0x80,0x00,0x00,0x00,0xFF,0xFF,0x1F,0xFE,0x00,0x00,0x00,0x07,0x00,0x00,0x40,0x06,0x00,0x00,0x00,0x00,0xFF,0xFE,0x1F,0xFE,0x00,0x00,0x00,0x07,0x80,0x02,0x80,0x01,0x10,0x00,0x00,0x00,0xBF,0xFE,0x3F,0xF8,0x00,0x00,0x00,0x07,0xC0,0x03,0x20,0x0D,0x30,0x00,0x00,0x00,0x1F,0xFE,0x3F,0xF0,0x00,0x00,0x00,0x03,0xC0,0x06,0x40,0x0F,0xF0,0x00,0x00,0x00,0x3F,0xFF,0x3F,0xF0,0x00,0x00,0x00,0x33,0xE0,0x07,0xD0,0x1F,0xE0,0x00,0x00,0x00,0x21,0xFF,0x7F,0xE0,0x00,0x00,0x00,0x3F,0xF0,0x1F,0x90,0x3F,0x80,0x00,0x00,0x00,0x01,0xFF,0x7F,0xC0,0x00,0x00,0x00,0x1F,0xF8,0x37,0xD0,0x1E,0x00,0x00,0x00,0x00,0xA7,0xFF,0x7F,0x80,0x00,0x00,0x00,0x0F,0xFC,0x7F,0xD0,0x06,0x00,0x00,0x00,0x00,0xBF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0xF9,0xFA,0xE0,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x77,0xE9,0x79,0x00,0x00,0x00,0x00,0x00,0x9F,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x2F,0xF9,0x18,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0x80,0x00,0x00,0x00,0x00,0x38,0x67,0x00,0x00,0x00,0x00,0x00,0x00,0x6B,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x78,0x04,0x80,0x00,0x0A,0x00,0x00,0x08,0xEB,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x98,0xA0,0x04,0x00,0x00,0x1C,0x00,0x03,0x8E,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x5F,0x00,0x00,0x00,0x00,0x18,0x00,0x07,0xF6,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x10,0x00,0x1F,0xE2,0x7F,0xFF,0xEF,0xE0,0x00,0x00,0x00,0x3E,0x02,0x00,0x00,0x00,0x00,0x00,0x1F,0xE6,0x7F,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x3E,0x1F,0xC0,0x00,0x00,0x00,0x00,0x1D,0xFC,0x9F,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x7E,0x30,0x20,0x00,0x00,0x0E,0x00,0x1F,0xF8,0x9F,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x7E,0x20,0x00,0x00,0x1C,0x08,0x00,0x0F,0x38,0x7F,0xFF,0xEB,0xF0,0x00,0x00,0x03,0xFE,0x41,0xC0,0x00,0x7E,0x08,0x00,0x00,0x7C,0x3F,0xFF,0xD7,0xE0,0x00,0x00,0x07,0xFE,0x43,0xE0,0x00,0xC1,0x80,0x00,0x00,0x18,0x7F,0xFF,0xE1,0xE0,0x00,0x00,0x00,0xFC,0x47,0xC0,0x00,0x80,0x04,0x00,0x02,0xF3,0x7F,0xFF,0xA3,0xE0,0x00,0x00,0x00,0x1C,0xC7,0xF0,0x00,0x00,0x02,0x00,0x05,0xFF,0x7F,0xFF,0xA3,0xE0,0x00,0x00,0x00,0x3E,0x07,0xF0,0x00,0x00,0x00,0x00,0x0F,0xFF,0x7F,0xFF,0xF7,0xE0,0x00,0x00,0x00,0x7C,0x07,0xE0,0x04,0x00,0x00,0x00,0x03,0xFF,0xFF,0xFF,0x63,0xE0,0x00,0x00,0x00,0xF8,0x03,0xE2,0x04,0x00,0x00,0x00,0x83,0xB3,0xFF,0xDF,0xC1,0xC0,0x00,0x00,0x00,0xF0,0x01,0xC1,0x00,0x00,0x00,0x00,0x83,0x93,0xFF,0x83,0xD3,0xC0,0x00,0x00,0x03,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x17,0xA4,0xFF,0x03,0xFF,0xE0,0x00,0x00,0x00,0x70,0x00,0x00,0x01,0x00,0x00,0x00,0x3F,0xAD,0xBF,0x87,0x69,0xE0,0x00,0x00,0x00,0xF0,0x00,0x0E,0x0F,0x00,0x00,0x03,0xFF,0xEF,0xFF,0x0E,0xE1,0xC0,0x00,0x00,0x00,0x10,0x00,0x07,0xFF,0x00,0x00,0x17,0xFF,0xFF,0x1F,0xFC,0xFF,0x80,0x00,0x00,0x00,0x38,0x00,0x07,0x03,0x00,0x00,0x4F,0xFF,0x8F,0x3F,0x3C,0xF0,0x00,0x00,0x00,0x00,0x28,0x00,0x02,0x02,0x00,0x02,0xDF,0xFF,0x0B,0xFE,0x0F,0xF8,0x00,0x00,0x10,0x00,0x78,0x00,0x01,0x8C,0x00,0x01,0x9F,0xF3,0x11,0xFE,0x0D,0xF8,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x3F,0xFF,0x53,0xBC,0x18,0xFF,0x00,0x00,0x86,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x1F,0xFE,0x3B,0x3F,0xE4,0x7F,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x47,0xE7,0xC2,0x7F,0xFB,0x24,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x20,0x18,0x13,0xEF,0x80,0xFE,0x7B,0x02,0x00,0x00,0x03,0x00,0x3E,0x00,0x78,0x00,0x20,0x12,0x01,0xEC,0x01,0xF8,0x1E,0x66,0x60,0x00,0x03,0x00,0xC7,0x01,0xF8,0x00,0x00,0x30,0x01,0x00,0x03,0xF8,0x3A,0xF2,0xD0,0x00,0x03,0x01,0x0F,0x03,0xF8,0x00,0x00,0x60,0x00,0xC0,0x07,0xFC,0x6E,0xF3,0xD8,0x00,0x03,0x02,0x09,0x81,0xF8,0x00,0x00,0xC0,0x00,0x00,0x1F,0x9E,0xB8,0xD0,0xE0,0x00,0x03,0x84,0x08,0xC1,0xF8,0x00,0x03,0x80,0x00,0x00,0xFB,0x13,0xF0,0x50,0xE0,0x80,0x03,0x88,0x08,0xF1,0xF0,0x00,0x00,0x00,0x00,0x00,0xF9,0x18,0xF0,0x00,0x01,0x80,0x07,0x00,0x00,0x7F,0xF0,0x00,0x00,0x00,0x00,0x38,0x7F,0xE8,0xC0,0x00,0x00,0x00,0x07,0x00,0x00,0x27,0xF0,0x00,0x00,0x00,0x03,0xF8,0x72,0x60,0xA0,0x00,0x00,0x00,0x07,0x00,0x00,0x37,0xF0,0x00,0x04,0x00,0x02,0x28,0x92,0xC0,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x4F,0xF8,0x00,0x01,0x00,0x00,0x78,0xB0,0x40,0x00,0x00,0x00,0x00,0x07,0xC0,0x00,0x1F,0xF8,0x00,0x0E,0x00,0x00,0x9E,0xCD,0xC0,0x00,0x00,0x00,0x00,0x07,0x80,0x00,0x1F,0xFC,0x00,0x0E,0x80,0x00,0x7D,0x1F,0x80,0x18,0x00,0x00,0x00,0x07,0x80,0x00,0x1F,0xFE,0x00,0x1F,0x00,0x00,0x82,0x00,0x00,0x38,0x00,0x00,0x00,0x07,0x80,0x01,0xFF,0xFF,0x00,0x3F,0x80,0x01,0x42,0x00,0x00,0x38,0x00,0x00,0x00,0x07,0x80,0x03,0xFF,0xFF,0x80,0x3F,0x80,0x00,0x00,0x00,0x00,0x30,0x8C,0x00,0x00,0x07,0xF8,0x03,0xFF,0xFF,0x80,0x3F,0x00,0x00,0x00,0x00,0x03,0xA3,0x88,0x00,0x00,0x07,0xF8,0x63,0xFF,0xFF,0x80,0x1E,0x00,0x00,0x00,0x00,0x03,0xC6,0x50,0x00,0x00,0x07,0xF8,0xFF,0xFF,0xFF,0x00,0x04,0x80,0x00,0x00,0x00,0x00,0x06,0x20,0x00,0x00,0x03,0xF9,0xFF,0xFF,0x9E,0x00,0x03,0x80,0x00,0x00,0x00,0x00,0x06},
    //  下面这个没问题 伤心
     {0x1F,0xFE,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xFF,0xF8,0x1F,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x10,0x0F,0xFF,0xF8,0x9F,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x10,0x0F,0xFF,0xF8,0x8F,0xFF,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x80,0x00,0x10,0x0B,0xFF,0xFF,0x4F,0xFF,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x07,0x80,0x00,0x10,0x09,0xFF,0xFF,0x17,0xFE,0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x01,0x80,0x00,0x40,0x01,0xFF,0xFF,0x3F,0xFE,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x07,0x80,0x00,0x20,0x00,0xFF,0xFE,0x3F,0xFE,0x00,0x00,0x00,0x07,0x80,0x00,0x00,0x03,0x90,0x00,0x00,0x00,0xFF,0xFE,0x3F,0xF8,0x00,0x00,0x00,0x07,0xC0,0x00,0x20,0x0F,0x30,0x00,0xE8,0x00,0xBF,0xFE,0x3F,0xF4,0x00,0x00,0x00,0x03,0xC0,0x00,0x40,0x0F,0xF0,0x00,0xA8,0x00,0x3F,0xFF,0x7F,0xE4,0x00,0x00,0x00,0x23,0xE0,0x00,0x00,0x1F,0xE0,0x00,0xA8,0x00,0x23,0xFF,0x7F,0xE0,0x00,0x00,0x00,0x3B,0xF0,0x01,0x10,0x3F,0x80,0x00,0xA0,0x00,0x00,0xFF,0x7F,0xC0,0x00,0x00,0x00,0x3F,0xF8,0x3C,0x10,0x7E,0x00,0x00,0x18,0x00,0x23,0xFF,0xFF,0x80,0x00,0x00,0x00,0x1F,0xFC,0x7F,0xF0,0x7C,0x00,0x00,0x58,0x00,0xBF,0xFF,0xFF,0xA0,0x00,0x00,0x00,0x01,0xFF,0xFF,0xE8,0x3C,0x00,0x00,0x50,0x01,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFC,0x88,0x00,0x00,0x60,0x01,0x9F,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x7C,0xFF,0xF8,0xC0,0x02,0x00,0x40,0x01,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x3D,0xFB,0xF9,0xA0,0x0C,0x00,0x00,0x01,0xEB,0xFF,0xFF,0x40,0x00,0x00,0x01,0x00,0x7F,0xFF,0xCF,0x80,0x38,0x00,0x00,0x19,0xEF,0xFF,0xFF,0xC0,0x00,0x00,0x01,0xB8,0xFF,0xFF,0x8F,0xC0,0xF4,0x00,0x07,0xBD,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x01,0xFF,0xFF,0x7F,0x8D,0x00,0xE0,0x00,0x0F,0xF9,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0xFF,0xFF,0xFE,0x72,0x00,0x68,0x00,0x0F,0xF6,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0xFF,0xFF,0x3E,0x03,0xE0,0x70,0x00,0x3F,0x27,0xFF,0xFF,0xFF,0xD0,0x00,0x00,0x00,0xFF,0xFD,0xDE,0x00,0x80,0x30,0x00,0x7F,0xFE,0xBF,0xFF,0xFF,0xD0,0x00,0x00,0x00,0x7F,0xF7,0xEC,0x00,0x00,0x30,0x00,0x7F,0xF8,0x9F,0xFF,0xFF,0xF0,0x00,0x00,0x1F,0xFF,0xEC,0x10,0x00,0x00,0x38,0x00,0x1F,0x78,0xFF,0xFF,0xFB,0xE0,0x00,0x00,0x0F,0xFF,0xF8,0x48,0x00,0x78,0x10,0x00,0x0C,0xFE,0xFF,0xFF,0xC7,0xE0,0x00,0x24,0x0B,0xFF,0xF1,0xE0,0x00,0xCE,0x18,0x00,0x00,0x18,0xFF,0xFF,0xF3,0xE0,0x00,0x40,0x00,0xDF,0xF1,0xC0,0x01,0x00,0x0E,0x00,0x00,0xF3,0xFF,0xFF,0x8F,0xE0,0x00,0x00,0x04,0xBF,0xE3,0xF0,0x00,0x00,0x0C,0x00,0x05,0xFF,0xFF,0xFF,0x83,0xE0,0x00,0x00,0x03,0x7F,0xE3,0xF4,0xE3,0x00,0x04,0x00,0x0F,0xFE,0xFF,0xFF,0xEF,0xC0,0x00,0x00,0x00,0xFF,0xE3,0xF1,0x00,0x80,0x00,0x00,0x17,0xFF,0xFF,0xFF,0xE3,0xC0,0x00,0x00,0x03,0x3F,0xE0,0x14,0x02,0x00,0x00,0x00,0x87,0xFF,0xFF,0xFF,0xE3,0xC0,0x00,0x00,0x07,0xFF,0x80,0x01,0x82,0x00,0x00,0x01,0x37,0xB3,0xFF,0x93,0xF3,0xC0,0x00,0x00,0x0F,0x7F,0x00,0x00,0x00,0x00,0x00,0x0B,0x9F,0xEC,0xFF,0x03,0xFF,0xC0,0x00,0x00,0x04,0x7E,0x00,0x00,0x00,0x00,0x02,0x00,0x3F,0xAB,0xFF,0x87,0xB9,0x80,0x00,0x00,0x00,0xFC,0x00,0x00,0x00,0x00,0x00,0x66,0x7F,0xE7,0xFF,0x1E,0xE3,0x80,0x00,0x00,0x00,0x3C,0x00,0x00,0xFE,0x00,0x00,0xF7,0xFF,0xDF,0x5F,0x3E,0xDF,0x80,0x00,0x00,0x00,0x7C,0x00,0x01,0xFF,0x00,0x01,0xF7,0xFF,0x8E,0x3F,0x7C,0xF8,0x80,0x00,0x00,0x00,0x1C,0x00,0x03,0xFF,0x80,0x07,0xFF,0xFF,0x1F,0xFF,0x1D,0x1C,0x80,0x00,0x7A,0x00,0x0C,0x00,0x07,0xC3,0x80,0x1F,0x9F,0xFB,0x19,0xFC,0x1F,0xFE,0x00,0x00,0x8E,0x00,0x02,0x00,0x07,0x01,0x80,0x00,0x3F,0xF3,0xFB,0xFE,0x0E,0xFF,0x00,0x00,0x06,0x00,0x01,0x00,0x06,0x00,0x00,0x1E,0x3F,0xEE,0xFB,0x7F,0xEC,0xFF,0xC0,0x00,0x06,0x00,0x00,0x00,0x00,0x00,0x01,0xB0,0x9F,0xE7,0xAB,0xFF,0xF1,0x7C,0x60,0x00,0x07,0x80,0x00,0x00,0x00,0x00,0x00,0x20,0x0F,0xFF,0xE7,0x9E,0x3B,0x64,0x20,0x00,0x03,0x80,0x3C,0x00,0x00,0x00,0x80,0x40,0x07,0xEA,0x8F,0xF8,0x3E,0xEE,0x62,0x00,0x03,0x00,0xC6,0x00,0xFF,0xF0,0x00,0x40,0x03,0x0D,0x0F,0xF0,0x1C,0xF3,0xF0,0x00,0x03,0x01,0x0B,0x03,0xF8,0x00,0x00,0x80,0x03,0xC0,0x07,0xF8,0x4D,0x92,0x98,0x00,0x06,0x02,0x09,0x83,0xF8,0x00,0x01,0x80,0x01,0x00,0x7F,0xBE,0xBA,0xF9,0xE8,0x00,0x07,0x84,0x09,0xC1,0xF8,0x00,0x03,0x00,0x00,0x0B,0xFE,0x17,0xB0,0x50,0xC0,0x00,0x07,0x88,0x10,0xE1,0xF0,0x00,0x02,0x00,0x00,0x17,0xF8,0x1A,0xE0,0x00,0x40,0x00,0x07,0x10,0x10,0xFB,0xF0,0x00,0x18,0x00,0x00,0x78,0x7F,0xB8,0xD0,0x84,0x60,0x00,0x06,0x00,0x00,0x5F,0xF0,0x00,0x1C,0x00,0x01,0xF8,0xFE,0x20,0xC0,0x00,0x6C,0x00,0x06,0x00,0x00,0x2F,0xF0,0x00,0x1E,0x00,0x03,0xF8,0x93,0xC0,0x00,0x00,0x80,0x00,0x0F,0x80,0x00,0x1F,0xF0,0x00,0x1E,0x00,0x14,0xF8,0x97,0x00,0x00,0x00,0x00,0x00,0x0F,0xC0,0x00,0x3F,0xF8,0x00,0x1F,0x00,0x0C,0x9E,0xEB,0x80,0x00,0x20,0x00,0x00,0x0F,0x80,0x00,0x3F,0xFC,0x00,0x1F,0x00,0x0B,0xFE,0x9F,0x00,0x18,0x38,0x00,0x00,0x0F,0x80,0x00,0x7F,0xFE,0x00,0x1F,0x80,0x09,0xFA,0x00,0x00,0x38,0x00,0x00,0x00,0x0F,0x00,0x03,0xFF,0xFF,0x00,0x3F,0x80,0x0B,0x42,0x00,0x00,0x38,0x00,0x00,0x00,0x0F,0x90,0x03,0xFF,0xFF,0x00,0x3F,0x80,0x00,0x00,0x00,0x07,0x30,0x0C,0x00,0x00,0x07,0xF0,0xC3,0xFF,0xFF,0x80,0x3F,0x80,0x00,0x00,0x00,0x07,0xE3,0x9C,0x00,0x00,0x07,0xF0,0xE7,0xFF,0xFF,0x80,0x1F,0x00,0x00,0x00,0x00,0x03,0xE7,0x50,0x00,0x00,0x07,0xF9,0xFF,0xFF,0xFF,0x00,0x0E,0x00,0x00,0x00,0x00,0x00,0xC6,0x00,0x00,0x00,0x03,0xFF,0xFF,0xFF,0xFE,0x00,0x03,0x80,0x00,0x00,0x00,0x10,0x2E},
    //  下面这个没问题 生气
     {0x61,0xFD,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x8F,0xFF,0xF0,0x61,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x8F,0xFF,0xF0,0xE3,0xFF,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x00,0x00,0x06,0x1F,0xFF,0xF8,0xE3,0xFF,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x0E,0x3F,0xFF,0xF8,0xE3,0xFF,0xF0,0x00,0x00,0x06,0x00,0x00,0x00,0x03,0x80,0x00,0x0C,0xFF,0xFF,0xF8,0xE7,0xFF,0xE0,0x00,0x00,0x0E,0x00,0x00,0x00,0x03,0xC0,0x00,0x01,0x87,0xFF,0xFC,0xC7,0xFF,0xC0,0x00,0x00,0x1C,0x00,0x00,0x00,0x03,0xE0,0x00,0x01,0x87,0xFF,0x9C,0xCF,0xFF,0x80,0x00,0x00,0x3C,0x00,0x00,0x00,0x03,0xE0,0x00,0x01,0x07,0xFF,0xFC,0xCF,0xFF,0x00,0x00,0x00,0x3C,0x00,0x00,0x00,0x03,0xE0,0x00,0x00,0x07,0xFF,0xFC,0x5F,0xFE,0x00,0x00,0x00,0x3C,0x00,0x00,0x00,0x03,0xF0,0x00,0x00,0x03,0xFF,0xFE,0xDF,0xFC,0x00,0x00,0x00,0x3C,0x00,0x01,0x00,0x07,0xF0,0x00,0x00,0x03,0xFF,0xFE,0xDF,0xFC,0x00,0x00,0x00,0x7E,0x00,0x01,0x02,0x1F,0xF0,0x00,0x00,0x03,0xFF,0xFE,0xFF,0xF8,0x00,0x00,0x00,0x7F,0x80,0x63,0x02,0x3F,0xF0,0x00,0x00,0x03,0xFF,0xFF,0x3F,0xF8,0x00,0x00,0x00,0x7F,0xF0,0x63,0x80,0x3F,0xE0,0x00,0x00,0x03,0xFF,0xFF,0xBF,0xE0,0x00,0x00,0x00,0x3F,0xF8,0x77,0x22,0x7F,0xE0,0x00,0x00,0x03,0xFF,0xFF,0xFC,0xC0,0x00,0x00,0x00,0x3F,0xFE,0x7F,0x60,0x7F,0x80,0x00,0x00,0x01,0xFF,0xFF,0xFD,0xC0,0x00,0x00,0x00,0x1F,0xFE,0x0F,0xE0,0x7F,0x00,0x00,0x00,0x03,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x0F,0xFE,0xB3,0xE0,0x1E,0x00,0x20,0x00,0x01,0xFF,0xFF,0xEF,0x80,0x00,0x00,0x00,0x01,0xF8,0xC9,0xE0,0x0E,0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0xF0,0x40,0xC0,0x06,0x01,0x00,0x00,0x01,0xFF,0xFF,0xF7,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xF7,0x00,0x00,0x00,0x0F,0x80,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xE6,0x80,0x00,0x00,0x0F,0xF0,0x20,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0xFF,0xFF,0xCF,0xC4,0x00,0x00,0x07,0xFC,0x40,0x00,0x00,0x18,0x10,0x00,0x00,0x00,0xFF,0xFF,0x9F,0x9C,0x00,0x00,0x00,0xFE,0x43,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xBC,0x00,0x00,0x02,0x3F,0x05,0x80,0x00,0x60,0x20,0x00,0x00,0x00,0xFF,0xFF,0x7F,0xFC,0x00,0x00,0x00,0x1F,0x08,0xC0,0x00,0xC0,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xF8,0x00,0x00,0x01,0x0F,0x08,0x60,0x01,0xE0,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFC,0x00,0x00,0x01,0x07,0x10,0xF8,0x01,0xE0,0x00,0x00,0x00,0x00,0xFF,0x0F,0xFF,0xF8,0x00,0x00,0x01,0x06,0x10,0xF9,0x99,0xF0,0x00,0x00,0x00,0x00,0xFE,0x02,0xFF,0xF8,0x00,0x00,0x02,0x02,0x10,0xF8,0x61,0xF0,0x00,0x00,0x00,0x00,0xFE,0x00,0x7F,0xF8,0x00,0x00,0x07,0xF9,0xC0,0xF9,0x8D,0xF0,0x00,0x00,0x00,0x00,0xFF,0xC0,0x63,0xF4,0x00,0x00,0x02,0x07,0x70,0xF9,0x88,0xE0,0x00,0x00,0x00,0x02,0xFF,0xF8,0x41,0xF0,0x00,0x00,0x01,0x07,0xF0,0xF0,0x00,0x40,0x00,0x00,0x00,0x0F,0xFF,0x80,0x60,0xF0,0x00,0x00,0x00,0x87,0x80,0x70,0x00,0x00,0x00,0x00,0x00,0x3F,0xFF,0x00,0xF1,0xF8,0x00,0x00,0x00,0x0F,0x00,0x00,0x12,0x00,0x00,0x00,0x00,0x3F,0xFF,0x70,0xFF,0xF8,0x00,0x00,0x00,0x3E,0x00,0x49,0xBE,0x00,0x00,0x00,0x00,0x7F,0xFF,0xC2,0xE3,0xF8,0x00,0x00,0x05,0xCE,0x00,0x1D,0xFE,0xC0,0x00,0x00,0x00,0x7F,0xFF,0x87,0xC1,0xFC,0x00,0x00,0x02,0x0E,0x00,0x1F,0xFF,0xE0,0x00,0x00,0x00,0xFF,0xFF,0x8F,0xF3,0xF6,0x00,0x00,0x01,0xE6,0x00,0x3F,0xFF,0xE0,0x00,0x00,0x3F,0xFB,0xFF,0xFF,0xFF,0x80,0x00,0x04,0x00,0x06,0x00,0x3E,0x07,0xE0,0x00,0x00,0x7F,0xE3,0xFF,0xFF,0xFF,0x00,0x00,0x02,0x00,0x1E,0x00,0x38,0x01,0xE0,0x00,0x00,0xFF,0xDF,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,0x79,0x00,0x20,0x00,0x60,0x00,0x2D,0xFE,0x3F,0xFF,0xFF,0x3E,0x00,0x00,0x10,0x00,0x00,0x80,0x20,0x02,0x60,0x01,0xDF,0xFC,0x77,0x9F,0x1F,0x1C,0x00,0x00,0x16,0x00,0x00,0x40,0x30,0x00,0x00,0x1C,0x7F,0xE1,0xEF,0x1F,0x1F,0x08,0x00,0x00,0x0A,0x80,0x00,0x20,0x00,0x00,0x00,0x39,0x1F,0xED,0xDE,0x1F,0x9C,0x00,0x00,0x00,0x02,0x00,0xFC,0x00,0x00,0x00,0x00,0x78,0x4F,0xFF,0xFF,0xE7,0xF2,0x00,0x00,0x00,0x02,0x03,0xFE,0x00,0x00,0x00,0x60,0xC8,0x27,0xFF,0xCF,0xAF,0xFB,0x00,0x20,0x00,0x02,0x07,0xFF,0x00,0x7C,0x00,0x63,0x88,0x03,0xFF,0x9F,0xBF,0xFC,0xA1,0xFE,0x00,0x02,0x1C,0x1F,0xC0,0xFC,0x00,0x0E,0x80,0x01,0xE7,0xFF,0xFF,0xF8,0x20,0xF6,0x00,0x02,0x30,0x1F,0xF9,0xFC,0x00,0x00,0x80,0x00,0xC7,0xFE,0x7F,0xF3,0x5C,0xC0,0x00,0x02,0x60,0x3F,0xFF,0xFC,0x00,0x01,0x00,0x00,0x81,0xFC,0x3D,0x5C,0x3F,0x84,0x00,0x03,0xC0,0x3F,0xFF,0xF8,0x00,0x00,0x00,0x00,0x1F,0xFE,0x7C,0x50,0x30,0x00,0x00,0x03,0x80,0x3F,0xFF,0xF8,0x00,0x04,0x00,0x00,0x7F,0xFD,0x7C,0x00,0x00,0x00,0x00,0x03,0x00,0x23,0xFF,0xF8,0x00,0x04,0x00,0x7F,0xFF,0xFC,0x6C,0x00,0x00,0x00,0x00,0x02,0x78,0x20,0x7F,0xF8,0x00,0x04,0x00,0xFF,0xFF,0xDE,0x00,0x00,0x00,0x00,0x00,0x05,0x02,0x24,0x3F,0xF0,0x00,0x03,0x01,0xAF,0xE0,0x1C,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0xA7,0xDF,0xF0,0x00,0x02,0x21,0x3F,0xC4,0x30,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x68,0x5F,0xF0,0x00,0x02,0xB3,0xFC,0x5E,0xE0,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x70,0x3F,0xF8,0x00,0x02,0x99,0xF0,0xF2,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0xC0,0x20,0x3F,0xFC,0x00,0x07,0x91,0xE3,0x80,0x00,0x00,0x20,0x00,0x00,0x00,0x03,0xC0,0x00,0x3F,0xFE,0x00,0x07,0xC7,0x07,0x80,0x00,0x00,0x10,0x00,0x00,0x00,0x03,0xC0,0x02,0x7F,0xFF,0x00,0x0F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xF0,0x03,0xFF,0xFF,0x80,0x0F,0xC0,0x00,0x00,0x00,0x00,0x00},
    //  下面这个没问题 兴奋
    //  {0x1F,0xFF,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x0F,0xFF,0xF8,0x1F,0x9F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x07,0xFF,0xF8,0x1F,0xFF,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x10,0x07,0xFF,0xF8,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x05,0xFF,0xFD,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x01,0xFF,0xFF,0x3F,0xFE,0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0xFF,0xFF,0x1F,0xFE,0x00,0x00,0x00,0x0F,0x00,0x00,0x00,0x1C,0x80,0x00,0x00,0x00,0xFF,0xFE,0x3F,0xFE,0x00,0x00,0x00,0x0C,0x80,0x00,0x00,0x12,0x80,0x00,0x00,0x00,0xFF,0xFE,0x3F,0xF8,0x00,0x00,0x00,0x0F,0x80,0x00,0x20,0x01,0x00,0x00,0x00,0x00,0x6F,0xFE,0x3F,0xF4,0x00,0x00,0x00,0x07,0xC0,0x04,0x10,0x1C,0x00,0x00,0x00,0x00,0x3F,0xFE,0x7F,0xE0,0x00,0x00,0x00,0x07,0xE0,0x24,0x40,0x06,0x00,0x00,0x00,0x00,0x33,0xFF,0x7F,0xE0,0x00,0x00,0x00,0x07,0xE0,0x06,0x80,0x22,0x00,0x00,0x00,0x00,0x01,0xFF,0x7F,0xC0,0x00,0x00,0x00,0x03,0xF8,0x06,0x80,0x32,0x00,0x00,0x00,0x00,0x03,0xFF,0x7F,0x80,0x00,0x00,0x00,0x3F,0xFE,0x1F,0xE4,0x0C,0x00,0x00,0x00,0x00,0xBF,0xFF,0xFF,0x80,0x00,0x00,0x00,0x3F,0xFF,0xBF,0xF0,0x04,0x00,0x00,0x00,0x00,0x7F,0xFF,0xFC,0x00,0x00,0x00,0x00,0x0F,0xFF,0xFC,0x20,0x00,0x00,0x00,0x00,0x00,0x1F,0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x3F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x7D,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x1F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x7B,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x07,0xC0,0x00,0x70,0x00,0x00,0x00,0x00,0x4B,0xFF,0xFE,0x50,0x00,0x00,0x00,0x00,0x03,0xFC,0x00,0x00,0x00,0x00,0x01,0x80,0xFF,0xFF,0xFF,0xE8,0x00,0x00,0x00,0x00,0x0B,0x62,0x00,0x00,0x10,0x00,0x0F,0xE0,0xFF,0xFF,0xFF,0xE8,0x00,0x00,0x00,0x00,0x77,0xC0,0x00,0x00,0x20,0x00,0x1F,0x82,0xFF,0xFF,0xFF,0xE0,0x00,0x00,0x00,0x40,0x0E,0x80,0x00,0x18,0x20,0x10,0x3F,0xC6,0xEF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x60,0x1F,0x8E,0x00,0x3E,0x00,0x00,0x1D,0xEE,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x76,0x3F,0x8F,0x00,0x62,0x00,0x00,0x7F,0xF8,0x9F,0xFF,0xFF,0xF0,0x00,0x00,0x03,0xFE,0x1F,0x8F,0x00,0x40,0x00,0x00,0x3F,0xFC,0x7F,0xFF,0xFF,0xF1,0x80,0x00,0x03,0xFE,0x07,0x8F,0x00,0x00,0x00,0x10,0x0C,0x7E,0x3F,0xFF,0xC7,0xE3,0xE0,0x00,0x01,0xFE,0x7F,0x8F,0x00,0x00,0x00,0x08,0x00,0x38,0xBF,0xFF,0xF3,0xE5,0xF0,0x00,0x0F,0xFF,0x3E,0x87,0x00,0x00,0x00,0x00,0x00,0xF3,0xFF,0xFF,0xC1,0xEF,0xF0,0x00,0x0F,0xFF,0x1C,0x00,0x01,0x00,0x00,0x00,0x0D,0xFF,0x7F,0xFF,0x81,0xEF,0xF0,0x00,0x03,0xFF,0x9C,0x00,0x20,0x10,0x00,0x00,0x0D,0xFF,0x7F,0xFF,0xEF,0xD0,0x80,0x00,0x00,0x9F,0x4C,0x00,0x00,0x30,0x00,0x00,0x33,0xFF,0x3F,0xFF,0x63,0xC0,0x00,0x00,0x00,0x7F,0xE6,0x01,0xFC,0x70,0x00,0x03,0x43,0xFF,0x7F,0xFF,0xE3,0xC1,0x00,0x00,0x00,0x3F,0xF2,0x00,0xFF,0xF0,0x00,0x05,0xC7,0x93,0x7F,0x97,0xF3,0xC4,0x00,0x00,0x00,0x1F,0xF8,0x00,0xFF,0xF0,0x00,0x07,0x87,0xEC,0x7F,0x03,0xFF,0xC0,0x00,0x00,0x00,0x0F,0xFE,0x00,0x78,0x20,0x00,0x01,0x1F,0xBC,0x7F,0x87,0x7D,0xC0,0x00,0x00,0x00,0x00,0x7F,0x00,0x3C,0x40,0x40,0x03,0x3F,0xCF,0x7F,0x0F,0xE1,0xC0,0x00,0x00,0x00,0x0F,0x7F,0x80,0x18,0x00,0x82,0x0F,0xFF,0xEF,0x1E,0x3C,0xC7,0x80,0x00,0x00,0x00,0x7F,0xFF,0xF8,0x00,0x03,0x03,0x9B,0xFF,0x9A,0x1F,0x7E,0xF9,0x80,0x00,0x00,0x00,0xBF,0xFF,0xDE,0x00,0x0E,0x06,0x47,0xFF,0x8F,0x7F,0x1D,0xE0,0x00,0x00,0x20,0x02,0xFF,0xFF,0xEF,0x00,0x04,0x0C,0x17,0xFF,0x13,0xFE,0x1D,0xF8,0x00,0x00,0x30,0x05,0xC2,0xFF,0xF7,0x00,0x00,0x0C,0x13,0xFB,0x53,0x7E,0x1E,0xFC,0x00,0x00,0x9B,0x0B,0x06,0xFF,0xFF,0x00,0x00,0x18,0x0B,0xFC,0xFF,0x6C,0x08,0xFE,0x00,0x00,0x8C,0x06,0x04,0xFF,0xF9,0x00,0x00,0x38,0x05,0xE4,0xFA,0x87,0xE1,0x7E,0x00,0x00,0x04,0x0C,0x04,0x7F,0xFC,0x00,0x00,0x68,0x01,0xFF,0x80,0x9E,0x7B,0x64,0x00,0x00,0x07,0x18,0x08,0x7F,0xFC,0x00,0x01,0xC8,0x00,0xF8,0x87,0xF8,0x3A,0x26,0x20,0x00,0x07,0x30,0x08,0x7F,0xFC,0x00,0x01,0x88,0x00,0x96,0x08,0xF0,0x3A,0xF6,0xF0,0x00,0x06,0x20,0x08,0x3F,0xF9,0x00,0x01,0x00,0x00,0x64,0x07,0xF8,0x1C,0x41,0x98,0x00,0x06,0x40,0x00,0x3F,0xF9,0x00,0x00,0x80,0x00,0x88,0x27,0xFC,0xE8,0x29,0x38,0x00,0x07,0x40,0x10,0x41,0xEF,0x00,0x00,0x40,0x00,0x01,0xFF,0x13,0xF0,0x40,0xC4,0x00,0x07,0x00,0x10,0x00,0xFA,0x00,0x00,0x00,0x00,0x01,0xF1,0x36,0xE0,0x00,0x41,0x00,0x06,0x00,0x00,0x00,0xFE,0x00,0x00,0x00,0x00,0x30,0x7B,0x38,0xC0,0x00,0x63,0x80,0x07,0x00,0x00,0x03,0xFE,0x00,0x00,0x00,0x0E,0x78,0xFA,0xF0,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0x01,0xFE,0x00,0x00,0x00,0x1E,0xC8,0x72,0xC0,0x60,0x00,0x00,0x00,0x07,0x00,0x00,0x1F,0xFC,0x00,0x00,0x00,0x7E,0x09,0xBA,0xC0,0x00,0x30,0x00,0x08,0x0F,0xC0,0x00,0x3F,0xFC,0x00,0x00,0x00,0x04,0x1F,0xC2,0x80,0x00,0x28,0x00,0x00,0x0D,0xC0,0x00,0x1F,0xFC,0x00,0x00,0x00,0x00,0x3E,0x96,0xC0,0x18,0x38,0x00,0x00,0x0F,0x80,0x00,0x1F,0xF8,0x00,0x00,0x00,0x01,0xFF,0x18,0x00,0x38,0x00,0x00,0x00,0x0F,0x80,0x01,0x9F,0xF8,0x00,0x00,0x00,0x0F,0x7C,0x00,0x00,0x38,0x00,0x00,0x00,0x0F,0x00,0x03,0xFF,0xF8,0x00,0x00,0x00,0x76,0x60,0x00,0x00,0x70,0x0C,0x00,0x00,0x0F,0x90,0x03,0xFF,0xF0,0x00,0x00,0x03,0x8A,0x00,0x00,0x03,0x31,0x8C,0x00,0x00,0x07,0xF0,0x43,0xFF,0xF0,0x00,0x03,0x00,0x00,0x00,0x00,0x03,0xA3,0xD8,0x00,0x00,0x06,0xF8,0xE3,0xFF,0xF0,0x00,0x03,0x80,0x00,0x00,0x00,0x01,0xC6,0x20,0x00,0x00,0x05,0xF9,0xFF,0xFF,0xB8,0x00,0x07,0xC0,0x00,0x00,0x00,0x00,0x26}
    };
#if 0
static uint16_t                      g_client_id = 0; /* 此处使用默认的client ID 0 */
#endif
static uint16_t g_conn_id = 0;
//连接ID
static ssapc_find_service_result_t g_find_service_result = {0};
// 服务发现结果

static void example_sle_start_scan(void);
//oled控制函数
void app_i2c_init_pin(void)
{
    uapi_pin_set_mode(CONFIG_I2C_SCL_MASTER_PIN, CONFIG_I2C_MASTER_PIN_MODE);
    uapi_pin_set_mode(CONFIG_I2C_SDA_MASTER_PIN, CONFIG_I2C_MASTER_PIN_MODE);
}

//OLED通知回调
static void example_oled_notification_cbk(uint8_t client_id, uint16_t conn_id, ssapc_handle_value_t *data)
{

  // 解析数据并控制OLED

    if (data->data_len == strlen("HAPPY") && data->data[0] == 'H' && data->data[1] == 'A' && data->data[2] == 'P' &&
        data->data[3] == 'P' && data->data[4] == 'Y') {

            ssd1306_DrawBitmap(myphoto[0],sizeof(myphoto));
            ssd1306_UpdateScreen();
    }

    if (data->data_len == strlen("SAD") && data->data[0] == 'S' && data->data[1] == 'A' &&
        data->data[2] == 'D') {
            ssd1306_DrawBitmap(myphoto[1],sizeof(myphoto));
            ssd1306_UpdateScreen();
    }

    if (data->data_len == strlen("ANGRY") && data->data[0] == 'A' && data->data[1] == 'N' && data->data[2] == 'G' &&
        data->data[3] == 'R' && data->data[4] == 'Y') {
            ssd1306_DrawBitmap(myphoto[2],sizeof(myphoto));
            ssd1306_UpdateScreen();
    }


    //将OLED状态写回服务器
    /* 将本端(Cient)的OLED等状态, 通过写请求发送给对端(Server) */
    ssapc_write_param_t param = {0};
    param.handle = g_find_service_result.start_hdl;
    param.type = SSAP_PROPERTY_TYPE_VALUE;
    param.data_len = data->data_len;

    param.data = osal_vmalloc(param.data_len);
    if (param.data == NULL) {
        PRINT("[SLE Client] write req mem fail\r\n");
        return;
    }

    if (memcpy_s(param.data, param.data_len, data, data->data_len) != EOK) {
        PRINT("[SLE Client] write req memcpy fail\r\n");
        osal_vfree(param.data);
        return;
    }
// ssapc_write_req(client_id, conn_id, &param);  发送写请求
    if (ssapc_write_req(client_id, conn_id, &param) != ERRCODE_SUCC) {
        PRINT("[SLE Client] write req fail\r\n");
        osal_vfree(param.data);
        return;
    }

    osal_vfree(param.data);
    return;
}
//扫描使能回调
static void example_sle_enable_cbk(errcode_t status)
{
    if (status == ERRCODE_SUCC) {
        example_sle_start_scan();
    }
}
//扫描开始回调
static void example_sle_seek_enable_cbk(errcode_t status)
{
    if (status == ERRCODE_SUCC) {
        return;
    }
}
//扫描停止回调
static void example_sle_seek_disable_cbk(errcode_t status)
{
    if (status == ERRCODE_SUCC) {
        sle_connect_remote_device(&g_remote_addr);// 连接设备
    }
}
//定义了一个静态全局数组 g_sle_expected_addr，用于存储预期的SLE设备地址  
static uint8_t g_sle_expected_addr[SLE_ADDR_LEN] = {0x04, 0x01, 0x06, 0x08, 0x06, 0x03};
// static uint8_t g_sle_expected_addr[SLE_ADDR_LEN] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};

//扫描结果回调，找到特定设备后停止扫描
//触发扫描的调用流程--扫描结果处理  如果找到目标设备（地址匹配），则停止扫描。
static void example_sle_seek_result_info_cbk(sle_seek_result_info_t *seek_result_data)
{
    
    if (seek_result_data == NULL) {
        //调试输出
        PRINT("[SLE Client] seek result seek_result_data is NULL\r\n");
        return;
    }

    if (memcmp((void *)seek_result_data->addr.addr, (void *)g_sle_expected_addr, SLE_ADDR_LEN) == 0) {
        PRINT("[SLE Client] seek result find expected addr:%02x***%02x%02x\r\n", seek_result_data->addr.addr[0],
              seek_result_data->addr.addr[4], seek_result_data->addr.addr[5]);
        (void)memcpy_s(&g_remote_addr, sizeof(sle_addr_t), &seek_result_data->addr, sizeof(sle_addr_t));
        sle_stop_seek();// 停止扫描
    }
}
// 回调函数注册
static void example_sle_seek_cbk_register(void)
{
    g_seek_cbk.sle_enable_cb = example_sle_enable_cbk;
    // 注册扫描使能回调
    g_seek_cbk.seek_enable_cb = example_sle_seek_enable_cbk;
    g_seek_cbk.seek_disable_cb = example_sle_seek_disable_cbk;
    g_seek_cbk.seek_result_cb = example_sle_seek_result_info_cbk;
}
//连接状态变化回调
static void example_sle_connect_state_changed_cbk(uint16_t conn_id,
                                                  const sle_addr_t *addr,
                                                  sle_acb_state_t conn_state,
                                                  sle_pair_state_t pair_state,
                                                  sle_disc_reason_t disc_reason)
{
    PRINT("[SLE Client] conn state changed conn_id:0x%x, addr:%02x***%02x%02x\r\n", conn_id, addr->addr[0],
          addr->addr[4], addr->addr[5]); /* 0 4 5: addr index */
    PRINT("[SLE Client] conn state changed disc_reason:0x%x\r\n", disc_reason);
    if (conn_state == SLE_ACB_STATE_CONNECTED) {
        if (pair_state == SLE_PAIR_NONE) {
            sle_pair_remote_device(&g_remote_addr);//发起配对
        }
        g_conn_id = conn_id;// 保存连接ID
    }
}
//配对完成回调，开始服务发现
static void example_sle_pair_complete_cbk(uint16_t conn_id, const sle_addr_t *addr, errcode_t status)
{
    PRINT("[SLE Client] pair complete conn_id:0x%x, status:0x%x, addr:%02x***%02x%02x\r\n", conn_id, status,
          addr->addr[0], addr->addr[4], addr->addr[5]); /* 0 4 5: addr index */
    if (status == ERRCODE_SUCC) {
        ssap_exchange_info_t info = {0};
        info.mtu_size = SLE_MTU_SIZE_DEFAULT;
        info.version = 1;
        ssapc_exchange_info_req(1, conn_id, &info); /* 此处没有使用默认的client ID 0 */
    }
}

static void example_sle_connect_cbk_register(void)
{
    g_connect_cbk.connect_state_changed_cb = example_sle_connect_state_changed_cbk;
    g_connect_cbk.pair_complete_cb = example_sle_pair_complete_cbk;
}
//SSAP服务发现与通信   --交换信息回调
static void example_sle_exchange_info_cbk(uint8_t client_id,
                                          uint16_t conn_id,
                                          ssap_exchange_info_t *param,
                                          errcode_t status)
{
    PRINT("[SLE Client] pair complete client id:0x%x, status:0x%x\r\n", client_id, status);
    PRINT("[SLE Client] exchange mtu, mtu size:0x%x, version:0x%x.\r\n", param->mtu_size, param->version);
    if (status == ERRCODE_SUCC) {
        ssapc_find_structure_param_t find_param = {0};
        find_param.type = SSAP_FIND_TYPE_PRIMARY_SERVICE;
        // 查找主服务
        find_param.start_hdl = 1;
        find_param.end_hdl = 0xFFFF;
        ssapc_find_structure(0, conn_id, &find_param); /* 此处使用默认的client ID 0 */
    }
}
//查找服务结构回调
static void example_sle_find_structure_cbk(uint8_t client_id,
                                           uint16_t conn_id,
                                           ssapc_find_service_result_t *service,
                                           errcode_t status)
{
    PRINT("[SLE Client] find structure cbk client:0x%x conn_id:0x%x status:0x%x \r\n", client_id, conn_id, status);
    PRINT("[SLE Client] find structure start_hdl:[0x%04x], end_hdl:[0x%04x], uuid len:0x%x\r\n", service->start_hdl,
          service->end_hdl, service->uuid.len);
    if (service->uuid.len == UUID_16BIT_LEN) {
        PRINT("[SLE Client] structure uuid:[0x%02x][0x%02x]\r\n", service->uuid.uuid[14],
              service->uuid.uuid[15]); /* 14 15: uuid index */
    } else {
        for (uint8_t idx = 0; idx < UUID_128BIT_LEN; idx++) {
            PRINT("[SLE Client] structure uuid[0x%x]:[0x%02x]\r\n", idx, service->uuid.uuid[idx]);
        }
    }

    if (status == ERRCODE_SUCC) {
        g_find_service_result.start_hdl = service->start_hdl;
        g_find_service_result.end_hdl = service->end_hdl;
        memcpy_s(&g_find_service_result.uuid, sizeof(sle_uuid_t), &service->uuid, sizeof(sle_uuid_t));
    }
}
//查找服务结构完成回调
static void example_sle_find_structure_cmp_cbk(uint8_t client_id,
                                               uint16_t conn_id,
                                               ssapc_find_structure_result_t *structure_result,
                                               errcode_t status)
{
    PRINT("[SLE Client] find structure cmp cbk client id:0x%x conn_id:0x%x status:0x%x type:%d uuid len:0x%x \r\n",
          client_id, conn_id, status, structure_result->type, structure_result->uuid.len);
    if (structure_result->uuid.len == UUID_16BIT_LEN) {
        PRINT("[SLE Client] find structure cmp cbk structure uuid:[0x%02x][0x%02x]\r\n",
              structure_result->uuid.uuid[14], structure_result->uuid.uuid[15]); /* 14 15: uuid index */
    } else {
        for (uint8_t idx = 0; idx < UUID_128BIT_LEN; idx++) {
            PRINT("[SLE Client] find structure cmp cbk structure uuid[0x%x]:[0x%02x]\r\n", idx,
                  structure_result->uuid.uuid[idx]);
        }
    }
}
//查找属性回调
static void example_sle_find_property_cbk(uint8_t client_id,
                                          uint16_t conn_id,
                                          ssapc_find_property_result_t *property,
                                          errcode_t status)
{
    PRINT(
        "[SLE Client] find property cbk, client id:0x%x, conn id:0x%x, operate ind:0x%x, handle:0x%x"
        "descriptors count:0x%x status:0x%x.\r\n",
        client_id, conn_id, property->operate_indication, property->handle, property->descriptors_count, status);
    for (uint16_t idx = 0; idx < property->descriptors_count; idx++) {
        PRINT("[SLE Client] find property cbk, descriptors type [0x%x]: 0x%02x.\r\n", idx,
              property->descriptors_type[idx]);
    }
    if (property->uuid.len == UUID_16BIT_LEN) {
        PRINT("[SLE Client] find property cbk, uuid: 0x%02x 0x%02x.\r\n", property->uuid.uuid[14],
              property->uuid.uuid[15]); /* 14 15: uuid index */
    } else if (property->uuid.len == UUID_128BIT_LEN) {
        for (uint16_t idx = 0; idx < UUID_128BIT_LEN; idx++) {
            PRINT("[SLE Client] find property cbk, uuid [0x%x]: 0x%02x.\r\n", idx, property->uuid.uuid[idx]);
        }
    }
}
//写入确定回调
static void example_sle_write_cfm_cbk(uint8_t client_id,
                                      uint16_t conn_id,
                                      ssapc_write_result_t *write_result,
                                      errcode_t status)
{
    PRINT("[SLE Client] write cfm cbk client id:0x%x conn_id:0x%x status:0x%x.\r\n", client_id, conn_id, status);
    PRINT("[SLE Client] write cfm cbk handle:0x%x, type:0x%x\r\n", write_result->handle, write_result->type);
}
//读写确认回调
static void example_sle_read_cfm_cbk(uint8_t client_id,
                                     uint16_t conn_id,
                                     ssapc_handle_value_t *read_data,
                                     errcode_t status)
{
    PRINT("[SLE Client] read cfm cbk client id:0x%x conn id:0x%x status:0x%x\r\n", client_id, conn_id, status);
    PRINT("[SLE Client] read cfm cbk handle:0x%x, type:0x%x, len:0x%x\r\n", read_data->handle, read_data->type,
          read_data->data_len);
    for (uint16_t idx = 0; idx < read_data->data_len; idx++) {
        PRINT("[SLE Client] read cfm cbk[0x%x] 0x%02x\r\n", idx, read_data->data[idx]);
    }
}
//通知回调(处理OLED控制)
static void example_sle_notification_cbk(uint8_t client_id,
                                         uint16_t conn_id,
                                         ssapc_handle_value_t *data,
                                         errcode_t status)
{
    PRINT("[SLE Client] notification cbk client id:0x%x conn id:0x%x status:0x%x\r\n", client_id, conn_id, status);

    PRINT("[SLE Client] notification cbk handle:0x%x, type:0x%x data len:0x%x \r\n", data->handle, data->type,
          data->data_len);

    for (uint16_t idx = 0; idx < data->data_len; idx++) {
        PRINT("[SLE Client] notification cbk[0x%x] 0x%02x\r\n", idx, data->data[idx]);
    }

    if (status == ERRCODE_SUCC) {
        example_oled_notification_cbk(client_id, conn_id, data);
    }
}
//指示回调
static void example_sle_indication_cbk(uint8_t client_id,
                                       uint16_t conn_id,
                                       ssapc_handle_value_t *data,
                                       errcode_t status)
{
    PRINT("[SLE Client] indication cbk client id:0x%x conn id:0x%x status:0x%x\r\n", client_id, conn_id, status);

    PRINT("[SLE Client] indication cbk handle:0x%x, type:0x%x data len:0x%x \r\n", data->handle, data->type,
          data->data_len);

    for (uint16_t idx = 0; idx < data->data_len; idx++) {
        PRINT("[SLE Client] indication cbk[0x%x] 0x%02x\r\n", idx, data->data[idx]);
    }
}

static void example_sle_ssapc_cbk_register(void)
{
    g_ssapc_cbk.exchange_info_cb = example_sle_exchange_info_cbk;
    g_ssapc_cbk.find_structure_cb = example_sle_find_structure_cbk;
    g_ssapc_cbk.find_structure_cmp_cb = example_sle_find_structure_cmp_cbk;
    g_ssapc_cbk.ssapc_find_property_cbk = example_sle_find_property_cbk;
    g_ssapc_cbk.write_cfm_cb = example_sle_write_cfm_cbk;
    g_ssapc_cbk.read_cfm_cb = example_sle_read_cfm_cbk;

    g_ssapc_cbk.notification_cb = example_sle_notification_cbk;
    // 注册通知回调
    g_ssapc_cbk.indication_cb = example_sle_indication_cbk;
}
//SLE扫描与连接   
//触发扫描的调用流程 -初始化阶段
static void example_sle_start_scan(void)
{
    sle_seek_param_t param = {0};
      // 设置扫描参数
    param.own_addr_type = 0;
    param.filter_duplicates = 0;
    param.seek_filter_policy = 0;
    param.seek_phys = 1;
    param.seek_type[0] = 0;
    param.seek_interval[0] = SLE_SEEK_INTERVAL_DEFAULT;// 设置扫描间隔
    param.seek_window[0] = SLE_SEEK_WINDOW_DEFAULT;// 设置扫描窗口
    sle_set_seek_param(&param);//将参数配置到SLE协议栈
    sle_start_seek();// 开始扫描
}
//主任务与启动
static int example_sle_oled_client_task(const char *arg)
{
    //以下为OLED相关代码
    uint32_t baudrate = I2C_SET_BANDRATE;
    uint32_t hscode = I2C_MASTER_ADDR;
    app_i2c_init_pin();
    errcode_t ret = uapi_i2c_master_init(1, baudrate, hscode);
    if (ret != 0) {
        printf("i2c init failed, ret = %0x\r\n", ret);
    }
    ssd1306_Init();
    ssd1306_Fill(Black);
    //以上为新增代码
    unused(arg);

    (void)osal_msleep(5000); /* 延时5s，等待SLE初始化完毕 */

    PRINT("[SLE Client] try enable.\r\n");
    //注册各种回调函数
    example_sle_seek_cbk_register();
    example_sle_connect_cbk_register();
    example_sle_ssapc_cbk_register();
    // 注册回调并启用SLE
    if (sle_announce_seek_register_callbacks(&g_seek_cbk) != ERRCODE_SUCC) {
        PRINT("[SLE Client] sle announce seek register callbacks fail !\r\n");
        return -1;
    }

    if (sle_connection_register_callbacks(&g_connect_cbk) != ERRCODE_SUCC) {
        PRINT("[SLE Client] sle connection register callbacks fail !\r\n");
        return -1;
    }

    if (ssapc_register_callbacks(&g_ssapc_cbk) != ERRCODE_SUCC) {
        PRINT("[SLE Client] sle ssapc register callbacks !\r\n");
        return -1;
    }
        
    if (enable_sle() != ERRCODE_SUCC) {
        PRINT("[SLE Client] sle enbale fail !\r\n");
        return -1;
    }
       // 注册回调到SLE系统
    // sle_announce_seek_register_callbacks(&g_seek_cbk);
    // sle_connection_register_callbacks(&g_connect_cbk);
    // ssapc_register_callbacks(&g_ssapc_cbk);
    // 启用SLE功能
    // enable_sle();
    return 0;
}

#define SLE_OLED_CLI_TASK_PRIO 24
#define SLE_OLED_CLI_STACK_SIZE 0x2000

static void example_sle_oled_client_entry(void)
{
    //创建任务线程
    osal_task *task_handle = NULL;

    osal_kthread_lock();
    task_handle = osal_kthread_create((osal_kthread_handler)example_sle_oled_client_task, 0, "SLEOLedClientTask",
                                      SLE_OLED_CLI_STACK_SIZE);// 创建线程
    if (task_handle != NULL) {
        osal_kthread_set_priority(task_handle, SLE_OLED_CLI_TASK_PRIO);
        osal_kfree(task_handle);
    }
    osal_kthread_unlock();
}

/* Run the example_sle_oled_client_entry. */
app_run(example_sle_oled_client_entry);// 启动应用